<template>
  <!-- <div class="list_container flex both-100">
    <Breadcrumb :title="pageTitle" />
    <Aside @handleNodeClick="handleNodeClick" />
    <div class="content_container">
      <el-form ref="searchMap" class="serach_wrapper flex-space-between" :inline="true" :model="searchMap" @submit.native.prevent>
        <div class="search">
          <el-form-item prop="noticeRuleName" size="small">
            <el-input v-model="searchMap.noticeRuleName" placeholder="通知规则名称" clearable @clear="getList()" @keyup.enter.native="getList()" />
          </el-form-item>
          <el-form-item class="flex">
            <el-button @click="handleSearch()" class="btn_primary">查询</el-button>
            <el-button @click="handleReset()" class="btn_cancel">重置</el-button>
          </el-form-item>
        </div>
        <div class="edit flex">
          <el-button icon="el-icon-plus" class="btn_primary" @click="handleAdd()">
            批量导入
          </el-button>
          <el-button icon="el-icon-plus" class="btn_primary" @click="handleAdd()">
            新增
          </el-button>
        </div>
      </el-form>
      <div class="table_container">
        <el-table stripe v-loading="loading" :data="projectList">
          <el-table-column type="index" label="序号" header-align="center" align="center" width="150"></el-table-column>
          <el-table-column prop="noticeRuleName" label="规则名称" header-align="center" align="center" width="150"></el-table-column>
          <el-table-column prop="noticeRuleDescribe" label="规则说明" align="center" width="150"></el-table-column>
          <el-table-column prop="enableStatus" label="状态" align="center">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.alarm_relus_enable_status" :value="scope.row.enableStatus" />
            </template>
          </el-table-column>
          <el-table-column prop="remark" label="备注" align="center"></el-table-column>
          <el-table-column label="操作" width="300" align="center">
            <template slot-scope="scope">
              <span type="text" class="tag_primary" size="small" @click="handleDetails(scope.row)">编辑</span>
              <span type="text" class="tag_warning" size="small" @click="handleDelete(scope.row)">删除</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination v-if="total>0" :total="total" :page.sync="searchMap.pageNum" :limit.sync="searchMap.pageSize" @change="getList" />
    </div>
  </div> -->

  <el-container class="user_container flex">
    <Aside @handleNodeClick="handleNodeClick" />
    <div class="list_container flex both-100">
      <Breadcrumb title="隐患排查" />
      <div class="content_container">
        <!-- 搜索模块 -->
        <el-form ref="searchMap" class="serach_wrapper flex-space-between" :inline="true" :model="searchMap" @submit.native.prevent>
          <div class="search">
            <el-form-item prop="noticeRuleName" size="small">
              <el-input v-model="searchMap.noticeRuleName" placeholder="通知规则名称" clearable @clear="getList()" @keyup.enter.native="getList()" />
            </el-form-item>
            <el-form-item class="flex">
              <el-button @click="handleSearch()" class="btn_primary">查询</el-button>
              <el-button @click="handleReset()" class="btn_cancel">重置</el-button>
            </el-form-item>
          </div>
          <div class="edit flex">
            <el-button icon="el-icon-plus" class="btn_primary" @click="handleAdd()">
              批量导入
            </el-button>
            <el-button icon="el-icon-plus" class="btn_primary" @click="handleAdd()">
              新增
            </el-button>
          </div>
        </el-form>
        <!-- 搜索模块over -->

        <!-- 表格模块 -->
        <div class="table_container">
          <!-- v-loading="loading" -->
          <el-table stripe v-loading="loading" :data="projectList">
            <el-table-column type="index" label="序号" header-align="center" align="center" width="150"></el-table-column>
            <el-table-column prop="noticeRuleName" label="规则名称" header-align="center" align="center" width="150"></el-table-column>
            <el-table-column prop="noticeRuleDescribe" label="规则说明" align="center" width="150"></el-table-column>
            <el-table-column prop="enableStatus" label="状态" align="center">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.alarm_relus_enable_status" :value="scope.row.enableStatus" />
              </template>
            </el-table-column>
            <el-table-column prop="remark" label="备注" align="center"></el-table-column>
            <el-table-column label="操作" width="300" align="center">
              <template slot-scope="scope">
                <span type="text" class="tag_primary" size="small" @click="handleDetails(scope.row)">编辑</span>
                <span type="text" class="tag_warning" size="small" @click="handleDelete(scope.row)">删除</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 表格模块over -->
        <!-- 分页 -->
        <Pagination v-show="total > 0" :total="total" :page.sync="searchMap.pageNum" :limit.sync="searchMap.pageSize" @change="getList"></Pagination>
        <!-- 分页over -->

      </div>
    </div>
    <NoticeDialog ref="noticeDialog" @replace="replace"></NoticeDialog>
  </el-container>

  <!-- 标签管理弹窗 start -->
  <!-- 标签管理弹窗 end -->

</template>
<script>
import { listNoticeRule, getNoticeRuleById, deleteNoticeRule } from '@/api'
import NoticeDialog from './NoticeDialog.vue';
import Aside from '@/components/Aside'
import { EventBus } from '@/utils/eventbus'

export default {
  dicts: ['alarm_relus_enable_status'],
  name: 'osiProject',
  data () {
    return {
      // 搜索数据
      searchMap: {
        pageNum: 1, // 当前页
        pageSize: 10,  // 默认条数 
        noticeRuleName: undefined,
      },
      // 表格加载状态
      loading: false,
      // 条数
      total: 0,
      // 考试数据列表数据
      projectList: [],
      // 题目选择弹框
      dialogQuestionVisable: false,
    };
  },
  created () {
    // this.getList()
    EventBus.$on('currentTree', (data) => {
      this.searchMap.deptId = data.id
      this.getList()
    })
  },
  computed: {
    pageTitle () {
      return '多级通知规则'
    }
  },
  methods: {
    // 获取列表
    async getList () {
      this.loading = true;
      const response = await listNoticeRule(this.searchMap)
      if (response.code === 200) {
        this.projectList = response.rows
        this.total = response.total
        this.loading = false
      }
    },
    // 点击详情
    async handleDetails (row) {
      const alarmNoticeRuleId = row.alarmNoticeRuleId
      const response = await getNoticeRuleById(alarmNoticeRuleId)
      this.$refs.noticeDialog.show(response.data)
    },
    // 删除
    handleDelete (row) {
      const alarmNoticeRuleId = [row.alarmNoticeRuleId]
      this.$confirm('是否删除该条数据').then(res => {
        return deleteNoticeRule(alarmNoticeRuleId)
      }).then(() => {
        this.getList()
        this.$message.success('删除成功')
      })
    },
    // 点击新增
    handleAdd () {
      this.$nextTick(() => {
        this.$refs.noticeDialog.show(this.searchMap.deptId)
      })
    },
    // 确定返回数据
    replace () {
      // this.getList()
    },
    // 查询
    handleSearch () {
      this.getList()
    },
    // 重置
    handleReset () {
      this.searchMap = {
        pageNum: 1, // 当前页
        pageSize: 10,  // 默认条数 
        noticeRuleName: undefined,
      },
        this.getList()
    },
    handleNodeClick (data) {
      this.searchMap.deptId = data.id
    },
  },
  components: {
    NoticeDialog,
    Aside
  },
  beforeDestroy: function () {
    EventBus.$off('currentTree');
  }
}
</script>
<style lang='less' scoped>
</style>